"""
线损管理数据模型
对应数据库表: dev_rtu_line_loss
"""
from datetime import datetime, date
from typing import Optional
from decimal import Decimal

from pydantic import BaseModel, Field, ConfigDict


class RtuLineLoss(BaseModel):
    """RTU线损数据模型"""
    id: int = Field(..., description="主键ID")
    calc_date: date = Field(..., description="计算日期")
    rtu_id: int = Field(..., description="RTU设备ID")
    rtu_code: Optional[str] = Field(None, max_length=32, description="RTU设备编码")
    rtu_consumption: Decimal = Field(..., description="RTU供电量(kWh)")
    meters_consumption: Decimal = Field(..., description="电表总用电量(kWh)")
    loss_kwh: Decimal = Field(..., description="线损电量(kWh)")
    loss_rate: Decimal = Field(..., description="线损率(%)")
    meter_count: int = Field(..., description="电表数量")
    valid_meter_count: int = Field(..., description="有效电表数量")
    data_quality: str = Field("NORMAL", max_length=20, description="数据质量标记")
    abnormal_flag: int = Field(0, description="异常标记")
    abnormal_type: Optional[str] = Field(None, max_length=50, description="异常类型")
    trend: Optional[str] = Field(None, max_length=10, description="趋势: up/down/flat")
    created_at: datetime = Field(..., description="创建时间")

    model_config = ConfigDict(from_attributes=True)
